/**
 * Copyright (c) 2018, wuyy All rights reserved.
 * wuyy 专有/保密源代码,未经许可禁止任何人通过任何渠道使用、修改源代码.
 * QQ:16349023
 * 项目名称 : com.wy2.eclipse.tool.lib
 * @version V1.0
 */
package com.wy2.eclipse.tool.lib;

import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.wy2.core.common.EncodingConsts;
import com.wy2.core.tool.JsonTools;
import com.wy2.eclipse.tool.lib.common.Constants;
import com.wy2.eclipse.tool.lib.entity.TemplateConfig;

/**
 * 模板配置管理器
 * @author wuyy<16349023@qq.com>
 * @date 2018年1月30日上午10:12:24
 * 
 */
public class TemplateConfigManager {
    private final static Logger logger = LoggerFactory.getLogger(TemplateConfigManager.class);

    private final File templateRootDirectory;

    public TemplateConfigManager(File templateRootDirectory) {
        super();
        this.templateRootDirectory = templateRootDirectory;
    }

    public File getTemplateRootDirectory() {
        return templateRootDirectory;
    } 
    
    public File getTemplateConfigFile() {
        return new File(getTemplateRootDirectory(), Constants.CONFIG_TEMPLATE_CONFIG_FILE);
    }
    
    public Boolean templateConfigExists() {
        return getTemplateConfigFile().exists();
    }
    
    public TemplateConfig loadTemplateConfig() {
        if(!templateConfigExists()) {
            return null;
        }
        TemplateConfig templateConfig=null;
        try {
            templateConfig = JsonTools.read(getTemplateConfigFile(), EncodingConsts.UTF_8, TemplateConfig.class);
        } catch (Exception e) {
            logger.error("加载模板配置信息异常", e);
        }
        return templateConfig;
    }
}
